#include "Player.hh"
#include <iostream>

Player::Player(const std::string& name)
    : Character(name, "Brave adventurers looking for a way to defeat evil wizards.", 20, 5, 2) {
    maxHealth = baseHealth;
}

unsigned Player::getMaxHealth() const {
    return maxHealth;
}

void Player::addToInventory(Item* item) {
    inventory.push_back(item);

    // Increased maximum health and current health
    if (item->healthBonus > 0) {
        maxHealth += item->healthBonus;
        currentHealth += item->healthBonus;
    }

    std::cout << "You've gotten it " << item->name << "!" << std::endl;

    if (item->healthBonus > 0) {
        std::cout << "Your health has increased " << item->healthBonus << "!" << std::endl;
    }
    if (item->attackBonus > 0) {
        std::cout << "Your Attack Power has been increased " << item->attackBonus << "!" << std::endl;
    }
    if (item->defenseBonus > 0) {
        std::cout << "Your defense has increased " << item->defenseBonus << "!" << std::endl;
    }
}

std::string Player::toString() const {
    return "Health: " + std::to_string(currentHealth) + "/" + std::to_string(maxHealth) +
        " | Attack: " + std::to_string(getAttack()) +
        " | Defense: " + std::to_string(getDefense());
}

// New takeDamage implementation
bool Player::takeDamage(unsigned damage) {
    unsigned actualDamage = (damage > getDefense()) ? (damage - getDefense()) : 0;

    if (actualDamage > currentHealth) {
        currentHealth = 0;
    }
    else {
        currentHealth -= actualDamage;
    }

    std::cout << getName() << " Received " << actualDamage << " damage! "
        << "Remaining health: " << currentHealth << "/" << maxHealth << std::endl;

    return (currentHealth == 0); // Returns whether it is dead or not
}


//这段代码实现了游戏中的一个玩家类 Player，继承自 Character 基类，包含生命管理、物品收集、属性加成和伤害处理等功能。




// This code implements a player class in the game, the Player, which inherits from the Character base class, and includes functions such as health management, item collection, attribute bonuses, and damage handling.
